package observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Doream
 * @Date: 2022/1/30 11:48
 */
public class SubjectImpl implements Subject {
    private List<Observer> observerList = new ArrayList<Observer>();
    @Override
    public void attach(Observer observer) {
        observerList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        observerList.remove(observer);
    }

    @Override
    public void notify(String message) {
        for (Observer observer : observerList) {
            observer.update(message);
        }
    }
}
